package cn.iocoder.yudao.module.shop.favorite.controller.app;

import cn.iocoder.yudao.framework.business.basic.pojo.dto.LocationQueryDTO;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.shop.favorite.service.AppShopFavoriteService;
import cn.iocoder.yudao.module.shop.favorite.vo.AppShopFavoriteVO;
import cn.iocoder.yudao.module.shop.info.vo.AppShopPrimaryReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/01/10
 */
@Tag(name = "用户 App - 店铺收藏")
@RestController
@RequestMapping("/shop/favorite")
@Validated
public class AppShopFavoriteController {
    @Resource
    private AppShopFavoriteService shopFavoriteService;
//    @Resource
//    private ShopInfoApi shopInfoApi;

    @PostMapping("/toggle")
    @Operation(summary = "收藏/取消收藏")
    public CommonResult<Boolean> toggle(@Valid @RequestBody AppShopPrimaryReqVO reqVO) {
        return success(shopFavoriteService.toggle(reqVO.getShopId(), getLoginUserId()));
    }

    @GetMapping("/page")
    @Operation(summary = "获得收藏分页")
    public CommonResult<PageResult<AppShopFavoriteVO>> page(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, @Valid LocationQueryDTO reqVO) {
        PageResult<AppShopFavoriteVO> data = shopFavoriteService.getPage(pageNo, pageSize, getLoginUserId());
//        Set<Long> shopIds = data.getList().stream().map(AdminShopFavoriteRespVO::getShopId).collect(Collectors.toSet());
//        // TODO 将结果按距离排序
//        shopInfoApi.getShopInfoList(shopIds);
        return success(data);
    }

}
